<!--
 * @Author: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @Date: 2024-08-29 10:59:23
 * @LastEditors: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @LastEditTime: 2024-09-24 17:52:36
 * @FilePath: \ft-apply-admin\src\views\ApplicationList\components\BatchModal.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <BasicModal :show="show" title="批量指派" width="30%" :widthComfirm="true" @comfirm="comfirm" @closeModal="closeModal">
    <template #content>
      <CommonForm v-if="show" :formList="formList" ref="formRef"></CommonForm>
    </template>
  </BasicModal>
</template>

<script setup lang="ts">
  import {comStores} from "../../../store/common/comStore";
  const store = comStores()
  const { userInFor } = store
  import CommonForm from "@/views/applicationDetails/CommonForm.vue";
  import BasicModal from "./BasicModal.vue";
  import { ref, watch } from "vue"
  import {IndexFormItem} from "../../applicationDetails/application-type";
  import { selectUserByRole,batchUpdateInterviewer,batchUpdatePreserveUser,batchUpdateInterviewUser } from '@/api/applay/applicationList/self'
  import {message} from "ant-design-vue";
  import tree from "../../dashboard/demo/tree";
  const show = ref<boolean>(false)
  const paramsList = () => ([
    { label: "约面HR", name: "userId", value: "", component: 'select', options: [] }
  ])
  const formList = ref<IndexFormItem[]>(paramsList())
  const emits = defineEmits(['onSuccess'])
  const formRef = ref<any>(null)
  const comfirm = async () => {
    const res = await formRef.value.submitForm();
    console.log(res, 'res');
    const param:any = {
      resumeInfos: resumeIds.value,
      operator: userInFor.userName
    }
    if(type.value === 'msg') {
      param.userName = res[0].value
    } else {
      param.userId = res[0].value
    }
    const data = type.value === 'msg' ? await batchUpdateInterviewer(param) : type.value === 'whhr' ? await batchUpdatePreserveUser(param) : await batchUpdateInterviewUser(param)
    if (data && data.code === '10000') {
      message.success("操作成功")
      emits('onSuccess')
      show.value = false
      formList.value = paramsList()
    } else {
      message.error(data.msg)
    }
  }
  watch(() => show.value, (val) => {
    if (val) {
      // getOptions()
    }
  })

  const getOptions = async () => {

    if(type.value === 'msg'){
      const userName = await selectUserByRole({request:'INTERVIEW', type:'1'}) //面试官
      formList.value[0].options = userName.data
      console.log('type.value',userName)
    } else{
      const userName = await selectUserByRole({request:'HR', type:'0'}) //面试官
      formList.value[0].options = userName.data
    }
  }
  const resumeIds = ref([]);
  const type = ref();
  const open = (params:Object) => {
    resumeIds.value = params.resumeIds
    type.value = params.type
    console.log('打开弹框', params.resumeIds)
    if(type.value === 'msg'){
      formList.value[0].label = '面试官'
      formList.value[0].name = 'userName'
    } else if(type.value === 'whhr'){
      formList.value[0].label = '维护HR'
      formList.value[0].name = 'userId'
    }
    getOptions()
    show.value = true
  }
  const closeModal = () => {
    show.value = false
    formList.value = paramsList()
  }
  defineExpose({ open })
</script>

<style lang="less" scoped>
</style>
